package com.kuizii.base.domain;

import lombok.Data;

import java.io.Serializable;

@Data
public class BaseResponse<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 自定义的错误码
     */
    public int httpStatus = 200;

    /**
     * 操作结果
     */
    public Integer optStatus = OptStatus.OK;

    public String message = "success";

    private String detailMsg;

    private T data;

    public BaseResponse(int optStatus) {

        this.optStatus = optStatus;
    }

    public BaseResponse(int code, String message, int optStatus) {
        this.httpStatus = code;
        this.message = message;
        this.optStatus = optStatus;
    }

    public BaseResponse(int code, String message) {
        this.httpStatus = code;
        this.message = message;
    }

    public static BaseResponse ok() {
        return new BaseResponse();
    }

    public BaseResponse() {
    }

    public BaseResponse(T data) {
        this.data = data;
    }

    public static BaseResponse ok(Object data) {
        return new BaseResponse(data);
    }

    public static BaseResponse fail(String message) {
        return fail(message, 200, null);
    }

    public static BaseResponse fail(String message, int code) {
        return fail(message, code, null);
    }

    public static BaseResponse fail(String message, int code, Object data) {
        final BaseResponse baseResponse = new BaseResponse(code, message);
        baseResponse.setOptStatus(-1);
        baseResponse.setData(data);
        return baseResponse;
    }

    public void setData(T data) {
        this.data = data;
    }
}
